<?php


// 应用公共文件
use app\common\SmsDemo;
use think\Loader;
use Qcloud\Sms\SmsSingleSender;
use Qcloud\Sms\SmsMultiSender;
use Qcloud\Sms\SmsVoiceVerifyCodeSender;
use Qcloud\Sms\SmsVoicePromptSender;
use Qcloud\Sms\SmsStatusPuller;
use Qcloud\Sms\SmsMobileStatusPuller;
use think\Session;
use think\Db;
use think\Request;
/*函数排序*/
ini_set ('memory_limit', '2048M');
function replace_unicode_escape_sequence($match) {
    return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}
function array_diff_assoc2_deep($array1, $array2) {
    $ret = array();
    foreach ($array1 as $k => $v) {
        if (!isset($array2[$k])) $ret[$k] = $v;
        else if (is_array($v) && is_array($array2[$k])) $ret[$k] = array_diff_assoc2_deep($v, $array2[$k]);
        else if ($v !=$array2[$k]) $ret[$k] = $v;
        else
        {
            unset($array1[$k]);
        }

    }
    return $ret;
}
function qrcode($url,$link)
{

    Loader::import('phpqrcode.phpqrcode', EXTEND_PATH);
   // $url = Request::instance()->domain().'/index.php/index/service_order/check_code/order_number/'.$order_number;
    $object = new \QRcode();
    $path = ROOT_PATH .'public'. $link;
    //第二个参数false的意思是不生成图片文件，如果你写上‘picture.png’则会在根目录下生成一个png格式的图片文件
    $ret = $object->png($url, $path,1, 10, 2);
    if($path === false){
        exit; //不生成图片
    }
    return $link;

}

/**
 * 生成签名
 * @return 签名，本函数不覆盖sign成员变量，如要设置签名需要调用SetSign方法赋值
 */
function MakeSign()
{
    $data = [
        'appid' => 'wx8598c19985700731',
        'mch_id' => '1516310811',
        'nonce_str' => random(16),
        'body' => '商品',
        'out_trade_no' => '20150806125346',
        'total_fee' => 1,
        'spbill_create_ip' => getIP()
        ];
    //签名步骤一：按字典序排序参数

    $string = ToUrlParams($data);

    //签名步骤二：在string后加入KEY
    $string = $string . "&key=".'09cblnzcygc4jw4orzdewhq7jf4deif5';
    //签名步骤三：MD5加密
    $string = md5($string);
    //签名步骤四：所有字符转为大写
    $result = strtoupper($string);
    return $result;
}
function ToUrlParams($data)
{
    $buff = "";
    foreach ($data as $k => $v)
    {
        if($k != "sign" && $v != "" && !is_array($v)){
            $buff .= $k . "=" . $v . "&";
        }
    }

    $buff = trim($buff, "&");
    return $buff;
}
function random($length = 16)
{
    $string = '';

    while (($len = strlen($string)) < $length) {
        $size = $length - $len;

        $bytes = function_exists('random_bytes') ? random_bytes($size) : mt_rand();

        $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
    }

    return $string;
}

//多维数组的差集
function array_diff_assoc_recursive($array1,$array2){
    $diffarray=array();
    foreach ($array1 as $key=>$value){
        //判断数组每个元素是否是数组
        if(is_array($value)){
            //判断第二个数组是否存在key
            if(!isset($array2[$key])){
                $diffarray[$key]=$value;
                //判断第二个数组key是否是一个数组
            }elseif(!is_array($array2[$key])){
                $diffarray[$key]=$value;
            }else{
                $diff=array_diff_assoc_recursive($value, $array2[$key]);
                if($diff!=false){
                    $diffarray[$key]=$diff;
                }
            }
        }elseif(!array_key_exists($key, $array2) || $value!==$array2[$key]){
            $diffarray[$key]=$value;
        }
    }
    return $diffarray;
}

function array_sort($arr,$keys,$type='asc'){
    $keysvalue = $new_array = array();
    foreach ($arr as $k=>$v){
        $keysvalue[$k] = $v[$keys];
    }
    if($type == 'asc'){
        asort($keysvalue);
    }else{
        arsort($keysvalue);
    }
    reset($keysvalue);
    foreach ($keysvalue as $k=>$v){
        $new_array[$k] = $arr[$k];
    }
    return $new_array;
}
/*
 * crypt + md5 混淆加密
 * @param  string $pass 密码明文
 */
function mcs($pass)
{
    return md5(md5($pass));
}

/*
 * 截取字符串
 */
function subtext($text, $length, $end = '...')
{
    if (mb_strlen($text, 'utf8') > $length)
        return mb_substr($text, 0, $length, 'utf8') . $end;
    return $text;
}

/*
 * 获取用户真实 IP
 */
function getIP()
{
    static $realIp;
    if (isset($_SERVER)) {
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
            $realIp = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
            $realIp = $_SERVER["HTTP_CLIENT_IP"];
        } else {
            $realIp = $_SERVER["REMOTE_ADDR"];
        }
    } else {
        if (getenv("HTTP_X_FORWARDED_FOR")) {
            $realIp = getenv("HTTP_X_FORWARDED_FOR");
        } else if (getenv("HTTP_CLIENT_IP")) {
            $realIp = getenv("HTTP_CLIENT_IP");
        } else {
            $realIp = getenv("REMOTE_ADDR");
        }
    }
    return $realIp;
}

/*
 * 成功提示函数
 * @param  string $msg 提示信息
 * @param  string $url 跳转地址
 * @param  integer $url 延时时间
 * @param  string $note 提示描述
 */
function win($msg, $url, $time = 2033, $note = "页面跳转中")
{

    $content = "<link rel='stylesheet' href='/static/console/css/sweet-alert.css'/><script src='/static/console/js/sweet-alert.min.js'></script><script>window.onload=myfun;countDown();function myfun(){swal('$msg','$note','success');delayURL(\"$url\",$time);document.querySelector('.confirm').onclick=function(){location.href='$url'}};function delayURL(url,time){setTimeout(\"top.location.href='\" + url + \"'\",time)}</script>";
    //$content = "<link rel='stylesheet' href='/static/console/css/sweet-alert.css'/><script src='/static/console/js/sweet-alert.min.js'></script><script>window.onload=myfun;countDown();function myfun(){swal('$msg','$note','success');delayURL(\"$url\",$time);document.querySelector('.confirm').onclick=function(){history.go(-2)}};function delayURL(url,time){setTimeout(\"history.go(-2)\",time)}</script>";
    abort(\think\Response::create($content, 'html'));
}
function wingo($msg, $url, $time = 2033, $note = "页面跳转中")
{

    //$content = "<link rel='stylesheet' href='/static/console/css/sweet-alert.css'/><script src='/static/console/js/sweet-alert.min.js'></script><script>window.onload=myfun;countDown();function myfun(){swal('$msg','$note','success');delayURL(\"$url\",$time);document.querySelector('.confirm').onclick=function(){location.href='$url'}};function delayURL(url,time){setTimeout(\"top.location.href='\" + url + \"'\",time)}</script>";
    $content = "<link rel='stylesheet' href='/static/console/css/sweet-alert.css'/><script src='/static/console/js/sweet-alert.min.js'></script><script>window.onload=myfun;countDown();function myfun(){swal('$msg','$note','success');delayURL(\"$url\",$time);document.querySelector('.confirm').onclick=function(){history.go(-2)}};function delayURL(url,time){setTimeout(\"history.go(-2)\",time)}</script>";
    abort(\think\Response::create($content, 'html'));
}
function winfo($msg, $url, $time = 2033, $note = "页面跳转中")
{

    //$content = "<link rel='stylesheet' href='/static/console/css/sweet-alert.css'/><script src='/static/console/js/sweet-alert.min.js'></script><script>window.onload=myfun;countDown();function myfun(){swal('$msg','$note','success');delayURL(\"$url\",$time);document.querySelector('.confirm').onclick=function(){location.href='$url'}};function delayURL(url,time){setTimeout(\"top.location.href='\" + url + \"'\",time)}</script>";
    $content = "<link rel='stylesheet' href='/static/console/css/sweet-alert.css'/><script src='/static/console/js/sweet-alert.min.js'></script><script>window.onload=myfun;countDown();function myfun(){swal('$msg','$note','success');delayURL(\"$url\",$time);document.querySelector('.confirm').onclick=function(){history.go(-1)}};function delayURL(url,time){setTimeout(\"history.go(-1)\",time)}</script>";
    abort(\think\Response::create($content, 'html'));
}

/*
 * 失败提示函数
 * @param  string $msg 提示信息
 * @param  integer $time 延时时间
 * @param  string $note 提示描述
 */
function fail($msg, $time = 2333, $note = "页面跳转中")
{
    $content = "<link rel='stylesheet' href='/static/console/css/sweet-alert.css'/><script src='/static/console/js/sweet-alert.min.js'></script><script>window.onload=myfun;function myfun(){swal('$msg','$note','error');delayURL(3000);document.querySelector('.confirm').onclick=function(){window.history.go(-1)}};function delayURL(time){setTimeout(\"window.history.go(-1);\",$time)};</script>";
    abort(\think\Response::create($content, 'html'));
}


/*
 * 没有权限提示函数
 * @param  string $msg 提示信息
 * @param  integer $time 延时时间
 * @param  string $note 提示描述
 */
function auth_fail($msg, $url, $time = 2333, $note = "页面跳转中")
{
    $content = "<link rel='stylesheet' href='/static/console/css/sweet-alert.css'/><script src='/static/console/js/sweet-alert.min.js'></script><script>window.onload=myfun;countDown();function myfun(){swal('$msg','$note','error');delayURL(\"$url\",$time);document.querySelector('.confirm').onclick=function(){location.href='$url'}};function delayURL(url,time){setTimeout(\"top.location.href='\" + url + \"'\",time)}</script>";
    abort(\think\Response::create($content, 'html'));
}

function fen(){
    //return (new Area())->province_list();
    db('test')->insert(['content' => time()]);
}
/*
 * 图片上传
 * @param string $img 图片名称
 */
function uploadImg($img = 'picUrl', $type = 'thumb')
{
    $file = request()->file($img);
    writeLogPic($file);
    if (!empty($file)) {

        // 移动到框架应用根目录/public/uploads/ 目录下
        $upload = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
        writeLogPic('upload:'.($upload));
        // halt($upload);
        if ($upload) {

            if ($type == 'thumb') {
                //图片处理
                //imgDispose('public' . DS . 'uploads' . DS . $upload->getSaveName());
            }

            //返回图片地址
            writeLogPic('ret:'.'uploads/' . date('Ymd') . '/' . $upload->getFilename());
            return 'uploads/' . date('Ymd') . '/' . $upload->getFilename();
        }
        writeLogPic('getError:'.$file->getError());
        return $file->getError();
    }

    return request()->param($img);
}
//递归
function getMenuList1($arr, $fid = 0,$parent_field = 'parenTid')
{
    $newArr = array();
    $i = 1;
    foreach ($arr as $v) {
        if ($v[$parent_field] == $fid) {
            $v['son'] = getMenuList1($arr, $v['id'],$parent_field);
            $newArr[]  = $v;
            $i++;
        }
    }
    return $newArr;
}	
// 多层递归前台使用
function getMenuList($arr, $fid = 0,$parent_field = 'parent_id')
{
    $newArr = array();
    $i = 1;
    foreach ($arr as $v) {
        if ($v[$parent_field] == $fid) {
            $v['son'] = getMenuList($arr, $v['id'],$parent_field);
            $newArr[]  = $v;
            $i++;
        }
    }
    return $newArr;
//    array(55) {
//    [0] => array(7) {
//        ["id"] => int(2)
//        ["cat_name"] => string(3) "AAa"
//        ["parent_id"] => int(0)
//        ["status"] => int(1)
//        ["sort"] => int(1)
//        ["multi_pic"] => string(124) "a:2:{i:0;s:47:"2 / 20180707 / 9a013e5eb201b25b538e466544fcd97f . png";i:1;s:47:"2 / 20180707 / 1a532fc1abe9889760055fc266ef913c . jpg";}"
//        ["son"] => array(1) {
//            [0] => array(7) {
//                ["id"] => int(26)
//                ["cat_name"] => string(12) "摄影摄像"
//                ["parent_id"] => int(2)
//                ["status"] => int(2)
//                ["sort"] => int(0)
//                ["multi_pic"] => string(0) ""
//                ["son"] => array(0) {
//                }
//      }
//    }
//  }
//  [1] => array(7) {
//        ["id"] => int(4)
//        ["cat_name"] => string(33) "家居、家具、家装、厨具"
//        ["parent_id"] => int(0)
//        ["status"] => int(1)
//        ["sort"] => int(0)
//        ["multi_pic"] => string(0) ""
//        ["son"] => array(0) {
//        }
//  }
//    }
}

// 多层递归前台使用
function getMenuTree($arrCat,$parent_id = 0,$field = 'parent_id',$level = 0,$str = '' )
{
    //$arrCat = array_sort($arrCat,'sort');
    static  $arrTree = array(); //使用static代替global
    if(empty($arrCat)) return FALSE;
    $level++;

    if($parent_id == 0){
        $str .= $parent_id;
    }else{
        $str .= ','.$parent_id;
    }

    //static $i = 0;

    foreach($arrCat as $key => $value)
    {
        //$i++;
        if($value[$field] == $parent_id)
        {
            $value['level'] = $level;
            $value['current_parent_str']= $str;
            $arrTree[] = $value;
            unset($arrCat[$key]); //注销当前节点数据，减少已无用的遍历
            getMenuTree($arrCat, $value[ 'id'],$field,$level,$str);
        }
    }
    return $arrTree;

//    array(68) {
//    [0] => array(7) {
//        ["id"] => int(2)
//        ["cat_name"] => string(3) "AAa"
//        ["parent_id"] => int(0)
//        ["status"] => int(1)
//        ["sort"] => int(1)
//        ["multi_pic"] => string(124) "a:2:{i:0;s:47:"2 / 20180707 / 9a013e5eb201b25b538e466544fcd97f . png";i:1;s:47:"2 / 20180707 / 1a532fc1abe9889760055fc266ef913c . jpg";}"
//        ["level"] => int(1)
//  }
//  [1] => array(7) {
//        ["id"] => int(26)
//        ["cat_name"] => string(12) "摄影摄像"
//        ["parent_id"] => int(2)
//        ["status"] => int(2)
//        ["sort"] => int(0)
//        ["multi_pic"] => string(0) ""
//        ["level"] => int(2)
//  }
//  }
}

// 多层递归前台使用
function getMenuTree1($arrCat,$parent_id = 0,$field = 'parent_id',$level = 0,$str = '' )
{

    static  $arrTree = array(); //使用static代替global
    if(empty($arrCat)) return FALSE;
    $level++;

    if($parent_id == 0){
        $str .= $parent_id;
    }else{
        $str .= ','.$parent_id;
    }

    //static $i = 0;

    foreach($arrCat as $key => $value)
    {
        //$i++;
        if($value[$field] == $parent_id)
        {
            $value['level'] = $level;
            $value['current_parent_str']= $str;
            $arrTree[] = $value;
            unset($arrCat[$key]); //注销当前节点数据，减少已无用的遍历
            getMenuTree1($arrCat, $value['manage_id'],$field = 'parent_id',$level,$str);
        }
    }
    if($parent_id != 0){
        $data = Db::name('salesman s')
            ->join('manager m','s.manage_id = m.id','left')
            ->field('m.username,m.nickname,m.create_time,s.*,m.id,m.telephone')
            ->where('m.level',4)
            ->where('manage_id',$parent_id)
            ->select()->toArray();
        $data_yewuyuan = Db::name('salesman s')
            ->join('manager m','s.manage_id = m.id','left')
            ->field('m.username,m.nickname,m.create_time,s.*,m.id,m.telephone')
            ->where('m.level',4)
            ->where('manage_id',$parent_id)
            ->select()->toArray();

        if(!empty($data_yewuyuan)){
            foreach ($data_yewuyuan as $k123 => &$v123){
                $v123['level'] = -1;
                $v123['member_count'] = Db::name('share_member s')->join('member m','m.id=s.member_id')->where('manage_id',$v123['manage_id'])->count();
                $v123['son_count'] = 1;
                $v123['telephone'] = hideStr($v123['telephone'],1,6);
            }
        }
        //$arrTree = array_merge($arrTree,$data_yewuyuan);
    }
    return $arrTree;

//    array(68) {
//    [0] => array(7) {
//        ["id"] => int(2)
//        ["cat_name"] => string(3) "AAa"
//        ["parent_id"] => int(0)
//        ["status"] => int(1)
//        ["sort"] => int(1)
//        ["multi_pic"] => string(124) "a:2:{i:0;s:47:"2 / 20180707 / 9a013e5eb201b25b538e466544fcd97f . png";i:1;s:47:"2 / 20180707 / 1a532fc1abe9889760055fc266ef913c . jpg";}"
//        ["level"] => int(1)
//  }
//  [1] => array(7) {
//        ["id"] => int(26)
//        ["cat_name"] => string(12) "摄影摄像"
//        ["parent_id"] => int(2)
//        ["status"] => int(2)
//        ["sort"] => int(0)
//        ["multi_pic"] => string(0) ""
//        ["level"] => int(2)
//  }
//  }
}

// 多层递归前台使用
function getMenuTree2($arrCat,$parent_id = 0,$field = 'parent_id',$level = 0,$str = '' )
{
    static  $arrTree1 = array(); //使用static代替global
    if(empty($arrCat)) return FALSE;
    $level++;

    if($parent_id == 0){
        $str .= $parent_id;
    }else{
        $str .= ','.$parent_id;
    }

    //static $i = 0;

    foreach($arrCat as $key => $value)
    {
        //$i++;
        if($value[$field] == $parent_id)
        {
            $value['level'] = $level;
            $value['current_parent_str']= $str;
            $arrTree1[] = $value;
            unset($arrCat[$key]); //注销当前节点数据，减少已无用的遍历
            getMenuTree2($arrCat, $value['manage_id'],$field = 'parent_id',$level,$str);
        }
    }
    \think\Cache::set('salesman_list',$arrTree1,7200);
    return $arrTree1;

//    array(68) {
//    [0] => array(7) {
//        ["id"] => int(2)
//        ["cat_name"] => string(3) "AAa"
//        ["parent_id"] => int(0)
//        ["status"] => int(1)
//        ["sort"] => int(1)
//        ["multi_pic"] => string(124) "a:2:{i:0;s:47:"2 / 20180707 / 9a013e5eb201b25b538e466544fcd97f . png";i:1;s:47:"2 / 20180707 / 1a532fc1abe9889760055fc266ef913c . jpg";}"
//        ["level"] => int(1)
//  }
//  [1] => array(7) {
//        ["id"] => int(26)
//        ["cat_name"] => string(12) "摄影摄像"
//        ["parent_id"] => int(2)
//        ["status"] => int(2)
//        ["sort"] => int(0)
//        ["multi_pic"] => string(0) ""
//        ["level"] => int(2)
//  }
//  }
}

function sonPath($arrCat,$parent_id = 0,$merge = false,$type = false)
{
    static $arrTree = array(); //使用static代替global
    if(empty($arrCat)) return FALSE;
    static $i = 0;
    foreach($arrCat as $key => $value)
    {
        $i++;
        if($value['parent_id' ] == $parent_id)
        {
            $arrTree[] = $value['id'];
            unset($arrCat[$key]); //注销当前节点数据，减少已无用的遍历
            sonPath($arrCat, $value[ 'manage_id']);
        }
    }
    if($merge){
        array_unshift($arrTree,$parent_id);//array_push
    }
    if($type){
        $stringTree = implode(',',$arrTree);
        return $stringTree;
    }
    //$stringTree = implode(',',$arrTree);
    return $arrTree;
    //false
//    array(1) {
//    [0] => int(26)
//}
//true    array(2) {
//    [0] => int(2)
//    [1] => int(26)
//}
}

function parentPath($cat_id,$table = 'Category',$type = false){
    //没有必要合并当前数据了.上级一般只用于面包屑
    //获取当前cat_id的该条信息 循环递归
   // $row = Db::name($table)->find($cat_id);
    $row = Db::name($table)->where('manage_id',$cat_id)->find();
    $tree = [];
    if($type){ //合并当前项
        if(!empty($row)){
            $tree[] = $row;//将该条数据放入数组中
        }

    }
    while($row['parent_id']>0){//只要该条数据的parent_id>0
        $row = Db::name($table)->where('manage_id',$row['parent_id'])->find();

        $tree[] = $row;
    }
    //array_reverse();返回翻转数据的数组
    return array_reverse($tree);//翻转数据
//    array(6) {
//        [0] => array(6) {
//            ["id"] => int(22)
//            ["cat_name"] => string(9) "冰箱123"
//            ["parent_id"] => int(0)
//            ["status"] => int(1)
//            ["sort"] => int(3)
//            ["multi_pic"] => string(0) ""
//  }
//  [1] => array(6) {
//            ["id"] => int(23)
//            ["cat_name"] => string(5) "冰-1"
//            ["parent_id"] => int(22)
//            ["status"] => int(1)
//            ["sort"] => int(0)
//            ["multi_pic"] => string(0) ""
//  }
//  [2] => array(6) {
//            ["id"] => int(24)
//            ["cat_name"] => string(5) "冰02"
//            ["parent_id"] => int(23)
//            ["status"] => int(2)
//            ["sort"] => int(1)
//            ["multi_pic"] => string(0) ""
//  }}
}
/*
 * 图片处理
 * @param string $img 图片名称
 */
function imgDispose($img = '')
{
    // 水印
    if ('true' == cache('web_watermark')) {

        if (cache('web_marktype') == '1')
            \think\Image::open(ROOT_PATH . $img)->water(ROOT_PATH . 'public' . DS . 'uploads' . DS . 'thumb_watermarket.png', cache('web_markwhere'), cache('web_transparent'))->save(ROOT_PATH . $img);
        else
            \think\Image::open(ROOT_PATH . $img)->text(cache('web_marktext'), ROOT_PATH . 'public' . DS . 'uploads' . DS . 'simsun.ttc', cache('web_transparent'), '#' . cache('web_markcolor'), cache('web_markwhere'))->save(ROOT_PATH . $img);
    }

    // 缩略图
    if ('true' == cache('web_thumb')) {

        \think\Image::open(ROOT_PATH . $img)->thumb(cache('web_thumbwide'), cache('web_thumbhigh'))->save(ROOT_PATH . get_thumb_pic($img));
    }

}



/*
 * 缩略图处理
 * @param string $img 图片名称
 */
function get_thumb_pic($img)
{
    $path = explode('/', $img);
    $count = count($path);
    $path[$count - 1] = "thumb_" . $path[$count - 1];
    return implode('/', $path);
}

function show_thumb_pic($img)
{
    $path = explode('/', $img);
    $count = count($path);
    $path[$count - 1] = "thumb_" . $path[$count - 1];
    return implode('/', $path);
}


// 组图上传
function multi_upload()
{
    // 接受流
    $file = request()->file();
    halt($file);
   //$a = $_FILES;
    write_log($file);
    //write_log('f'.$file);
    //write_log(halt($file));
    //halt(34124);
    $result = [];
    for ($i = 0; $i < count($file); $i++) {
        $info = $file[$i]->move(ROOT_PATH . 'public' . DS . 'uploads');
        //write_log('hah'.$info);
        $result[] = ['path' => 'uploads/' . date('Ymd') . '/' . $info->getFilename()];
    }

    //write_log('hah'.json_encode($result));
    //halt(1);
    //halt('g'.$result);
    if (empty($result)) return '';

    //halt(1);
    return serialize($result);
}

function emp($shop_assignor_records_id){

    $data = Db::name('shop_assignor_records sar')
        ->join('order o','o.id = sar.order_id','left')
        ->join('shop', 'shop.id = sar.shop_id', 'left')
        ->join('shop_assignor sa', 'sar.assignor_id = sa.id', 'left')
        ->join('single s','sar.single_id = s.id','left')
        ->where('sar.id', $shop_assignor_records_id)
        ->field('sar.*,shop.shop_title,sa.name,o.order_number,o.order_type,s.cat_name assignor_content')
        ->find();

    if(empty($data)){
//        dump(0);

//        dump($shop_assignor_records_id);
        emp($shop_assignor_records_id-1);
    }else{
//        dump(1);
        dump($data);
        return $arrTree;
    }
}

// 组图上传
function multi_upload3()
{
    // 接受流
    $file = request()->file();


    $result = [];
    for ($i = 0; $i < count($file); $i++) {
        $info = $file[$i]->move(ROOT_PATH . 'public' . DS . 'uploads');

        $result[] = ['path' => 'uploads/' . date('Ymd') . '/' . $info->getFilename()];
    }

    if (empty($result)) return '';

    return serialize($result);
}

function write_log($data){
    $years = date('Y-m');
    //设置路径目录信息
    $url = './log1/'.$years.'/'.date('Ymd').'_request_log.txt';
    $dir_name=dirname($url);
    //目录不存在就创建
    if(!file_exists($dir_name))
    {
        //iconv防止中文名乱码
        $res = mkdir(iconv("UTF-8", "GBK", $dir_name),0777,true);
    }
    $fp = fopen($url,"a");//打开文件资源通道 不存在则自动创建
    fwrite($fp,var_export($data,true)."\r\n");//写入文件
    fclose($fp);//关闭资源通道
}

function writeLogMic($data){
    $years = date('Y-m');
    //设置路径目录信息
    $url = './log1/'.$years.'/'.date('Ymd').'_request_log.txt';
    $dir_name=dirname($url);
    //目录不存在就创建
    if(!file_exists($dir_name))
    {
        //iconv防止中文名乱码
        $res = mkdir(iconv("UTF-8", "GBK", $dir_name),0777,true);
    }
    $fp = fopen($url,"a");//打开文件资源通道 不存在则自动创建
    fwrite($fp,var_export($data,true)."\r\n");//写入文件
    fclose($fp);//关闭资源通道
}
//请确保项目文件有可写权限，不然打印不了日志。
function writeLogAlipay($text) {
    // $text=iconv("GBK", "UTF-8//IGNORE", $text);
    //$text = characet ( $text );
    file_put_contents ( "./log.txt", date ( "Y-m-d H:i:s" ) . "  " . $text . "\r\n", FILE_APPEND );
}


/*
 * 数组分组
 *
 * @param object $data 二维数组
 * @param object $obj 对象
 */
function arrayGrouping($data, $val, $title, $list)
{
    if (empty($data)) return [];

    $result = array_values(array_reduce($data, function ($value, $key) use ($val, $title, $list) {
        $name = $key[$val];
        unset($key[$val]);
        $value[$name][$title] = $name;
        $value[$name][$list][] = $key;
        return $value;
    }));

    return $result;
}

/*
 * 一维数组 变成 二位数组
 *
 * @param object $data 一维数组
 * @param object $obj 名称
 */
function arrayChange($data, $title, $list)
{
    if (empty($data)) return [];
    $result = [];
    $n = 0;
    foreach ($data as $key => $value) {
        $result[$n][$title] = $key;
        $result[$n][$list] = array_values($value);
        $n++;
    }
    return $result;
}


/*
 * 递归节点
 * @param $multi 递归数组
 * @param int $parent_id 父级id
 * @return array
 */
function recursion_node($multi, $parent_id = 0, $name = 'classify', $variable = 'parenTid', $variable2 = 'id')
{

    if (empty($multi)) return false;
    $result = [];
    foreach ($multi as $item) {

        if ($item[$variable] == $parent_id) {

            $item[$name] = recursion_node($multi, $item[$variable2], $name, $variable, $variable2);


            if (empty($item[$name])) $item[$name] = [];
            $result[] = $item;
        }
    }

    return $result;
}

/*
 * 生成parentStr
 * @param $multi 生成parentStr
 * @param int $parenTid 父级id
 * @param int $id 条id
 * @param int $repId 上级id
 * @return array
 */
function parentStr($parenTid = '', $table = '', $id = '', $repId = '', $table2 = '')
{
    if (!empty($id))
        return \app\common\trilateral\Classify::UpParentStr($parenTid, $id, $repId, $table, $table2);
    else
        return \app\common\trilateral\Classify::GetParentStr($parenTid, $table);
}

/*
 * 生成count
 * @param $multi 生成count
 * @param int $parenTid 父级id
 * @param int $id 条id
 * @return array
 */
function ruleCount($parenTid = '', $table = '', $id = '')
{

    if (!empty($id))
        return \app\common\trilateral\Classify::countUpdate($id, $parenTid, $table);
    else
        return \app\common\trilateral\Classify::countAdd($parenTid, $table);
}

/*
 * 生成sku
 * @param $multi 生成sku
 * @param int $len 长度
 * @param int $sign 默认长度
 * @return array
 */
function SpecSku($len, $sign)
{
    if ($len < $sign) {
        echo "for (var i_" . $len . "=0; i_" . $len . "<spec_group_checked[" . $len . "].length; i_" . $len . "++){td_" . (intval($len) + 1) . " = spec_group_checked[" . $len . "][i_" . $len . "];\n";
        $len++;
        SpecSku($len, $sign);

    } else {
        echo "var tmp_spec_td = new Array();\n";
        for ($i = 0; $i < $len; $i++) {
            echo "tmp_spec_td[" . ($i) . "] = td_" . ($i + 1) . "[1];\n";
        }
        echo "tmp_spec_td.sort(function(a,b){return a-b});\n";
        echo "var spec_bunch = 'i_';\n";
        for ($i = 0; $i < $len; $i++) {
            echo "spec_bunch += tmp_spec_td[" . ($i) . "];\n";
        }
        echo "str += '<input type=\"hidden\" name=\"spec['+spec_bunch+'][goods_id]\" nc_type=\"'+spec_bunch+'|goods_id\" value=\"\" />';";
        for ($i = 0; $i < $len; $i++) {
            echo "if (td_" . ($i + 1) . "[2] != null) { str += '<input type=\"hidden\" name=\"spec['+spec_bunch+'][color]\" value=\"'+td_" . ($i + 1) . "[1]+'\" />';}";
            echo "str +='<td><input type=\"hidden\" name=\"spec['+spec_bunch+'][sp_value]['+td_" . ($i + 1) . "[1]+']\" value=\"'+td_" . ($i + 1) . "[0]+'\" />'+td_" . ($i + 1) . "[0]+'</td>';\n";
        }
        echo "str +='<td><input class=\"text stock\" type=\"text\" name=\"spec['+spec_bunch+'][stock]\" data_type=\"stock\" nc_type=\"'+spec_bunch+'|stock\" value=\"\" /></td><td><input class=\"text price\" type=\"text\" name=\"spec['+spec_bunch+'][price]\" data_type=\"price\" nc_type=\"'+spec_bunch+'|price\" value=\"\" /></td></tr>';\n";
        for ($i = 0; $i < $len; $i++) {
            echo "}\n";
        }



    }


}

function ff(){
    echo 'ff';
}
function SpecSku2($len, $sign)
{
    if ($len < $sign) {
        echo "for (var i_" . $len . "=0; i_" . $len . "<spec_group_checked[" . $len . "].length; i_" . $len . "++){td_" . (intval($len) + 1) . " = spec_group_checked[" . $len . "][i_" . $len . "];\n";
        $len++;
        SpecSku2($len, $sign);
    } else {
        echo "var tmp_spec_td = new Array();\n";
        for ($i = 0; $i < $len; $i++) {
            echo "tmp_spec_td[" . ($i) . "] = td_" . ($i + 1) . "[1];\n";
        }
        echo "tmp_spec_td.sort(function(a,b){return a-b});\n";
        echo "var spec_bunch = 'i_';\n";
        for ($i = 0; $i < $len; $i++) {
            echo "spec_bunch += tmp_spec_td[" . ($i) . "];\n";
        }
        echo "str += '<input type=\"hidden\" name=\"new['+spec_bunch+'][goods_id]\" nc_type=\"'+spec_bunch+'|goods_id\" value=\"\" />';";
        for ($i = 0; $i < $len; $i++) {
            echo "if (td_" . ($i + 1) . "[2] != null) { str += '<input type=\"hidden\" name=\"spec['+spec_bunch+'][color]\" value=\"'+td_" . ($i + 1) . "[1]+'\" />';}";
            echo "str +='<td><input type=\"hidden\" name=\"new['+spec_bunch+'][sp_value]['+td_" . ($i + 1) . "[1]+']\" value=\"'+td_" . ($i + 1) . "[0]+'\" />'+td_" . ($i + 1) . "[0]+'</td>';\n";
        }
        echo "str +='<td><input class=\"text stock\" type=\"text\" name=\"new['+spec_bunch+'][stock]\" data_type=\"stock\" nc_type=\"'+spec_bunch+'|stock\" value=\"\" /></td></tr>';\n";
        for ($i = 0; $i < $len; $i++) {
            echo "}\n";
        }
    }
}

function SpecSku33($len, $sign)
{
    if ($len < $sign) {
        echo "for (var i_" . $len . "=0; i_" . $len . "<spec_group_checked[" . $len . "].length; i_" . $len . "++){td_" . (intval($len) + 1) . " = spec_group_checked[" . $len . "][i_" . $len . "];\n";
        $len++;
        SpecSku($len, $sign);
    } else {
        echo "var tmp_spec_td = new Array();\n";
        for ($i = 0; $i < $len; $i++) {
            echo "tmp_spec_td[" . ($i) . "] = td_" . ($i + 1) . "[1];\n";
        }
        echo "tmp_spec_td.sort(function(a,b){return a-b});\n";
        echo "var spec_bunch = 'i_';\n";
        for ($i = 0; $i < $len; $i++) {
            echo "spec_bunch += tmp_spec_td[" . ($i) . "];\n";
        }
        echo "str += '<input type=\"hidden\" name=\"spec['+spec_bunch+'][goods_id]\" nc_type=\"'+spec_bunch+'|goods_id\" value=\"\" />';";
        for ($i = 0; $i < $len; $i++) {
            echo "if (td_" . ($i + 1) . "[2] != null) { str += '<input type=\"hidden\" name=\"spec['+spec_bunch+'][color]\" value=\"'+td_" . ($i + 1) . "[1]+'\" />';}";
            echo "str +='<td><input type=\"hidden\" name=\"spec['+spec_bunch+'][sp_value]['+td_" . ($i + 1) . "[1]+']\" value=\"'+td_" . ($i + 1) . "[0]+'\" />'+td_" . ($i + 1) . "[0]+'</td>';\n";
        }
        echo "str +='<td><input type=\"hidden\" name=\"spec['+spec_bunch+'][id]\" nc_type=\"'+spec_bunch+'|id\" value=\"\" /><input class=\"text marketprice\" type=\"text\" name=\"spec['+spec_bunch+'][marketprice]\" data_type=\"marketprice\" nc_type=\"'+spec_bunch+'|marketprice\" value=\"\" /><em class=\"add-on\"><i class=\"icon-renminbi\"></i></em></td><td><input class=\"text price\" type=\"text\" name=\"spec['+spec_bunch+'][price]\" data_type=\"price\" nc_type=\"'+spec_bunch+'|price\" value=\"\" /><em class=\"add-on\"><i class=\"icon-renminbi\"></i></em></td><td><input class=\"text stock\" type=\"text\" name=\"spec['+spec_bunch+'][stock]\" data_type=\"stock\" nc_type=\"'+spec_bunch+'|stock\" value=\"\" /></td><td><input class=\"text stock\" type=\"text\" name=\"spec['+spec_bunch+'][alarm]\" data_type=\"alarm\" nc_type=\"'+spec_bunch+'|alarm\" value=\"\" /></td><td><input class=\"text sku\" type=\"text\" name=\"spec['+spec_bunch+'][sku]\" nc_type=\"'+spec_bunch+'|sku\" value=\"\" /></td></tr>';\n";
        for ($i = 0; $i < $len; $i++) {
            echo "}\n";
        }
    }
}


// 字符串截取
function reStrLen($str, $len=10, $etc='...')
{
    $reStr = '';
    $i = 0;
    $n = 0.0;

    //字符串的字节数
    $strlen = strlen($str);
    while(($n < $len) and ($i < $strlen))
    {
        $temp_str = substr($str, $i, 1);

        //得到字符串中第$i位字符的ASCII码
        $ascnum = ord($temp_str);

        //如果ASCII位高与252
        if($ascnum >= 252)
        {
            //根据UTF-8编码规范，将6个连续的字符计为单个字符
            $reStr = $reStr.substr($str, $i, 6);
            //实际Byte计为6
            $i = $i + 6;
            //字串长度计1
            $n++;
        }
        else if($ascnum >= 248)
        {
            $reStr = $reStr.substr($str, $i, 5);
            $i = $i + 5;
            $n++;
        }
        else if($ascnum >= 240)
        {
            $reStr = $reStr.substr($str, $i, 4);
            $i = $i + 4;
            $n++;
        }
        else if($ascnum >= 224)
        {
            $reStr = $reStr.substr($str, $i, 3);
            $i = $i + 3 ;
            $n++;
        }
        else if ($ascnum >= 192)
        {
            $reStr = $reStr.substr($str, $i, 2);
            $i = $i + 2;
            $n++;
        }

        //如果是大写字母 I除外
        else if($ascnum>=65 and $ascnum<=90 and $ascnum!=73)
        {
            $reStr = $reStr.substr($str, $i, 1);
            //实际的Byte数仍计1个
            $i = $i + 1;
            //但考虑整体美观，大写字母计成一个高位字符
            $n++;
        }

        //%,&,@,m,w 字符按1个字符宽
        else if(!(array_search($ascnum, array(37, 38, 64, 109 ,119)) === FALSE))
        {
            $reStr = $reStr.substr($str, $i, 1);
            //实际的Byte数仍计1个
            $i = $i + 1;
            //但考虑整体美观，这些字条计成一个高位字符
            $n++;
        }

        //其他情况下，包括小写字母和半角标点符号
        else
        {
            $reStr = $reStr.substr($str, $i, 1);
            //实际的Byte数计1个
            $i = $i + 1;
            //其余的小写字母和半角标点等与半个高位字符宽
            $n = $n + 0.5;
        }
    }

    //超过长度时在尾处加上省略号
    if($i < $strlen)
    {
        $reStr = $reStr.$etc;
    }

    return $reStr;
}

// 字符串截取
function str_len($str, $len=10, $etc='...')
{
    $reStr = '';
    $i = 0;
    $n = 0.0;

    //字符串的字节数
    $strlen = strlen($str);
    while(($n < $len) and ($i < $strlen))
    {
        $temp_str = substr($str, $i, 1);

        //得到字符串中第$i位字符的ASCII码
        $ascnum = ord($temp_str);

        //如果ASCII位高与252
        if($ascnum >= 252)
        {
            //根据UTF-8编码规范，将6个连续的字符计为单个字符
            $reStr = $reStr.substr($str, $i, 6);
            //实际Byte计为6
            $i = $i + 6;
            //字串长度计1
            $n++;
        }
        else if($ascnum >= 248)
        {
            $reStr = $reStr.substr($str, $i, 5);
            $i = $i + 5;
            $n++;
        }
        else if($ascnum >= 240)
        {
            $reStr = $reStr.substr($str, $i, 4);
            $i = $i + 4;
            $n++;
        }
        else if($ascnum >= 224)
        {
            $reStr = $reStr.substr($str, $i, 3);
            $i = $i + 3 ;
            $n++;
        }
        else if ($ascnum >= 192)
        {
            $reStr = $reStr.substr($str, $i, 2);
            $i = $i + 2;
            $n++;
        }

        //如果是大写字母 I除外
        else if($ascnum>=65 and $ascnum<=90 and $ascnum!=73)
        {
            $reStr = $reStr.substr($str, $i, 1);
            //实际的Byte数仍计1个
            $i = $i + 1;
            //但考虑整体美观，大写字母计成一个高位字符
            $n++;
        }

        //%,&,@,m,w 字符按1个字符宽
        else if(!(array_search($ascnum, array(37, 38, 64, 109 ,119)) === FALSE))
        {
            $reStr = $reStr.substr($str, $i, 1);
            //实际的Byte数仍计1个
            $i = $i + 1;
            //但考虑整体美观，这些字条计成一个高位字符
            $n++;
        }

        //其他情况下，包括小写字母和半角标点符号
        else
        {
            $reStr = $reStr.substr($str, $i, 1);
            //实际的Byte数计1个
            $i = $i + 1;
            //其余的小写字母和半角标点等与半个高位字符宽
            $n = $n + 0.5;
        }
    }

    //超过长度时在尾处加上省略号
    if($i < $strlen)
    {
        $reStr = $reStr.$etc;
    }

    return $reStr;
}


function put_file_from_url_content($url, $saveName, $path) {
    // 设置运行时间为无限制
    set_time_limit ( 0 );

    $url = trim ( $url );
    $curl = curl_init ();
    // 设置你需要抓取的URL
    curl_setopt ( $curl, CURLOPT_URL, $url );
    // 设置header
    curl_setopt ( $curl, CURLOPT_HEADER, 0 );
    // 设置cURL 参数，要求结果保存到字符串中还是输出到屏幕上。
    curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
    // 运行cURL，请求网页
    $file = curl_exec ( $curl );
    // 关闭URL请求
    curl_close ( $curl );
    // 将文件写入获得的数据
    $filename = $path . $saveName;
    $write = @fopen ( $filename, "w" );
    if ($write == false) {
        return false;
    }
    if (fwrite ( $write, $file ) == false) {
        return false;
    }
    if (fclose ( $write ) == false) {
        return false;
    }


}


// 剩余时间
function gettime($time_s,$time_n){
    // $time_s = strtotime($time_s);
    // $time_n = strtotime($time_n);
    $strtime = '';
    $time = $time_n-$time_s;

    if($time >= 86400){
        return $strtime = date('Y-m-d H:i:s',$time_n);
    }
    if($time >= 3600){
        $strtime .= intval($time/3600).'小时';
        $time = $time % 3600;
    }else{
        $strtime .= '';
    }
    if($time >= 60){
        $strtime .= intval($time/60).'分钟';
        $time = $time % 60;
    }else{
        $strtime .= '';
    }
    if($time > 0){
        $strtime .= intval($time).'秒前';
    }else{
        $strtime = "时间错误";
    }
    return $strtime;
}

function sendSMSS($phone, $content)
{

    $yourAccessKeyId  = "LTAI9lQFD5Jf2l0h";
    $yourAccessKeySecret = "UJk2PhWFtFSHJqFIOACxfyzn1lM1AZ";
    $sms = new SmsDemo($yourAccessKeyId, $yourAccessKeySecret);

    $signName = "阿里云短信测试专用";
    $templateCode = "SMS_106000075";
    $code = array(
        "code"=>"【Ishop】".$content,
    );

    $response = $sms->sendSms($signName,$templateCode,$phone,$code);

    return $response;
}

function file_get_contents_post($url, $post){
//    $curl = curl_init();
// //设置抓取的url
//   curl_setopt($curl, CURLOPT_URL, $url);
//     //设置头文件的信息作为数据流输出
//     curl_setopt($curl, CURLOPT_HEADER, 1);
//      //设置获取的信息以文件流的形式返回，而不是直接输出。
//      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//      //设置post方式提交
//   curl_setopt($curl, CURLOPT_POST, 1);
//    //设置post数据
//     $post_data = $post;
//     curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
//     //执行命令
//     $data = curl_exec($curl);
//     //关闭URL请求
//    curl_close($curl);
//     //显示获得的数据
//
//return $data;
    $options = array(CURLOPT_RETURNTRANSFER =>true,CURLOPT_HEADER =>false,CURLOPT_POST =>true,CURLOPT_POSTFIELDS => $post,);
    $ch = curl_init($url);
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
};

function  curl_post1($url,$post){

    $options = array(CURLOPT_RETURNTRANSFER =>true,CURLOPT_HEADER =>false,CURLOPT_POST =>true,CURLOPT_POSTFIELDS => $post,);
    $ch = curl_init($url);
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

function sendSMS1($phone, $content)
{
    $yourAccessKeyId  = "LTAIrQfi5MFvwYAa";
    $yourAccessKeySecret = "mwNq9dskpNBu9gOj8t8IhP6snE1rxG";
    $sms = new SmsDemo($yourAccessKeyId, $yourAccessKeySecret);

    $signName = "善食元";
    $templateCode = "SMS_140915081";
    $code = array(
        "code"=> $content,
    );

    $response = $sms->sendSms($signName,$templateCode,$phone,$code);

    return $response;
}
function sendSMS($phone, $content)
{
    $yourAccessKeyId  = "LTAIIX7kpZ0hUckr";
    $yourAccessKeySecret = "CD2ooC0swnTXaLg7bfwbYbQ3Ky0wBS";
    $sms = new SmsDemo($yourAccessKeyId, $yourAccessKeySecret);

    $signName = "小毛驴车管家";
    $templateCode = "SMS_145485477";
    $code = array(
        "code"=> $content,
    );

    $response = $sms->sendSms($signName,$templateCode,$phone,$code);

    return $response;
}
function sendSMStxy($phone,$content){


    // 短信应用SDK AppID
    $appid = 1400092815; // 1400开头

// 短信应用SDK AppKey
    $appkey = "cb1af932861fab16fd1fda208453cb65";

// 需要发送短信的手机号码
    $phoneNumbers = [$phone, "12345678902", "12345678903"];

// 短信模板ID，需要在短信应用中申请
    $templateId = 7839;  // NOTE: 这里的模板ID`7839`只是一个示例，真实的模板ID需要在短信控制台中申请
    $params = [findNum($content),1];
// 签名
    $smsSign = "腾讯云"; // NOTE: 这里的签名只是示例，请使用真实的已申请的签名，签名参数使用的是`签名内容`，而不是`签名ID`
// 单发短信
    try {
        $ssender = new SmsSingleSender($appid, $appkey);
//        $result = $ssender->send(0, "86", $phoneNumbers[0],
//            findNum($content)."为您的验证码，请于1分钟内填写。如非本人操作，请忽略本短信。", "", "");
        $result = $ssender->sendWithParam(86, $phone, 122684, $params,
            "高原狼", "", "");

        $rsp = json_decode($result);
        //dump($rsp);
        if($rsp->result == 0) return 1;

    } catch(\Exception $e) {
        //return $e->getMessage();
       echo var_dump($e->getMessage());
    }
}

function findNum($str=''){
    $str=trim($str);
    if(empty($str)){return '';}
    $result='';
    for($i=0;$i<strlen($str);$i++){
        if(is_numeric($str[$i])){
            $result.=$str[$i];
        }
    }
    return $result;
}

/**
 * GET 请求
 * @param string $url
 */
function http_gets($url){
    $oCurl = curl_init();
    if(stripos($url,"https://")!==FALSE){
        curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
    }
    curl_setopt($oCurl, CURLOPT_URL, $url);
    curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
    $sContent = curl_exec($oCurl);
    $aStatus = curl_getinfo($oCurl);
    curl_close($oCurl);
    if(intval($aStatus["http_code"])==200){
        return $sContent;
    }else{
        return false;
    }
}

/**
 * curl
 */
function http_request($url, $data = null)
{

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        $data = json_encode($data);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }

    curl_setopt($curl, CURLOPT_HEADER, 0);

    curl_setopt($curl, CURLOPT_HTTPHEADER,

        array(

            'Content-Type: application/json; charset=utf-8',

            'Content-Length:' . strlen($data))

    );

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}

function writeLogOrder($data){
    $years = date('Y-m-d');
    //设置路径目录信息
    $url = './writeLog/'.$years.'/'.request()->controller().'_'.request()->action().'.txt';
    $dir_name=dirname($url);
    //目录不存在就创建
    if(!file_exists($dir_name))
    {
        //iconv防止中文名乱码
        $res = mkdir(iconv("UTF-8", "GBK", $dir_name),0777,true);
    }
    $fp = fopen($url,"a");//打开文件资源通道 不存在则自动创建
    fwrite($fp,date('Y-m-d H:i:s',time()).' '.var_export($data,true)."\r\n");//写入文件
    fclose($fp);//关闭资源通道
}

function writeLog($data){
    $years = date('Y-m-d');
    //设置路径目录信息
    $url = './kaijiang/'.$years.'/'.request()->controller().'_'.request()->action().'.txt';
    $dir_name=dirname($url);
    //目录不存在就创建
    if(!file_exists($dir_name))
    {
        //iconv防止中文名乱码
        $res = mkdir(iconv("UTF-8", "GBK", $dir_name),0777,true);
    }
    $fp = fopen($url,"a");//打开文件资源通道 不存在则自动创建
    fwrite($fp,date('Y-m-d H:i:s',time()).' '.var_export($data,true)."\r\n");//写入文件
    fclose($fp);//关闭资源通道
}



/*
* 生成订单号码
*/
function order_number()
{
    //订单号码主体（YYYYMMDDHHIISSNNNNNNNN）
    $order_id_main = date('YmdHis') . rand(10000000, 99999999);
    //订单号码主体长度
    $order_id_len = strlen($order_id_main);
    $order_id_sum = 0;
    for ($i = 0; $i < $order_id_len; $i++) {
        $order_id_sum += (int)(substr($order_id_main, $i, 1));
    }
    //唯一订单号码（YYYYMMDDHHIISSNNNNNNNNCC）
    $order_id = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100, 2, '0', STR_PAD_LEFT);

    return $order_id;
}

/*
 * 生成店铺订单号码
 */
function shop_order_number($shop_id)
{
    return date('YmdHis', time())
        . mt_rand(10, 99)
        . sprintf('%010d', time() - 946656000)
        . sprintf('%03d', (float)microtime() * 1000)
        . sprintf('%03d', (int)$shop_id % 1000);

}

/**
 * POST 请求
 * @param string $url
 * @param array $param
 * @param boolean $post_file 是否文件上传
 * @return string content
 */
function http_post($url,$param,$post_file=false){
    $oCurl = curl_init();
    if(stripos($url,"https://")!==FALSE){
        curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
    }
    if (PHP_VERSION_ID >= 50500 && class_exists('\CURLFile')) {
        $is_curlFile = true;
    } else {
        $is_curlFile = false;
        if (defined('CURLOPT_SAFE_UPLOAD')) {
            curl_setopt($oCurl, CURLOPT_SAFE_UPLOAD, false);
        }
    }
    if (is_string($param)) {
        $strPOST = $param;
    }elseif($post_file) {
        if($is_curlFile) {
            foreach ($param as $key => $val) {
                if (substr($val, 0, 1) == '@') {
                    $param[$key] = new \CURLFile(realpath(substr($val,1)));
                }
            }
        }
        $strPOST = $param;
    } else {
        $aPOST = array();
        foreach($param as $key=>$val){
            $aPOST[] = $key."=".urlencode($val);
        }
        $strPOST =  join("&", $aPOST);
    }
    curl_setopt($oCurl, CURLOPT_URL, $url);
    curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt($oCurl, CURLOPT_POST,true);
    curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);
    $sContent = curl_exec($oCurl);
    $aStatus = curl_getinfo($oCurl);
    curl_close($oCurl);
    if(intval($aStatus["http_code"])==200){
        return $sContent;
    }else{
        return false;
    }
}
function audinggift2($data)
{

    if (\request()->action() == 'create') {

        //有添加操作就是有权限 //有可能创建人就是审核人
        $data->create_time = date('Y-m-d H:i:s', time());
        $data->update_time = date('Y-m-d H:i:s', time());
        $data->create_id = Session::get('manage_id');
        $data->reason = '';

        if (isset($data->auding_status)) { //有审核状态 审核权限人
            //多次审核
            $role_id = session('role_id');
            //管理员2 一级审核员11 二级审核员12 三级审核员13
            if($role_id == 2 || $role_id == 11){
                $data->auding_status1 = $data->auding_status;

            }
            if($role_id == 12){
                $data->auding_status2 = $data->auding_status;
            }
            if($role_id == 13){
                $data->auding_status3 = $data->auding_status;
            }
            $data->auding_status = 1;
        }

    } else {

        if (isset($data->auding_status)) { //有审核状态 审核权限人 2是审核成功
            //多次审核
            $role_id = session('role_id');
            //管理员2 一级审核员11 二级审核员12 三级审核员13
            $status = false;
            $auding_status1 = Db::name('gift')->where('id',$data->id)->value('auding_status1');
            $auding_status2 = Db::name('gift')->where('id',$data->id)->value('auding_status2');
            $auding_status3 = Db::name('gift')->where('id',$data->id)->value('auding_status3');
            if($role_id == 2 || $role_id == 11){
                $data->auding_status1 = $data->auding_status;
                if($data->auding_status == 2 && $auding_status2 == 2 && $auding_status3 ==2){ //这有这一种情况是审核通过 其他全部是失败
                    $status = true;
                }

            }
            if($role_id == 12){ //2级审核
                if($auding_status1 != 2){
                    fail('请等一级审核完毕');
                }
                $data->auding_status2 = $data->auding_status;
                if($data->auding_status == 2 && $auding_status1 == 2 && $auding_status3 ==2){ //这有这一种情况是审核通过 其他全部是失败
                    $status = true;
                }
            }
            if($role_id == 13){
                if($auding_status2 != 2 || $auding_status1 != 2){
                    fail('请等一、二级审核完毕');
                }
                $data->auding_status3 = $data->auding_status;
                if($data->auding_status == 2 && $auding_status1 == 2 && $auding_status2 ==2){ //这有这一种情况是审核通过 其他全部是失败
                    $status = true;
                }
            }
            if($role_id == 1){
                if($data->auding_status == 2){ //审核通过
                    $status = true;
                    $data->auding_status1 = 2;
                    $data->auding_status2 = 2;
                    $data->auding_status3 = 2;
                }else{
                    $data->auding_status1 = 1;
                    $data->auding_status2 = 1;
                    $data->auding_status3 = 1;
                }

            }
            if($status == true){
                if($auding_status3 == 2 && $auding_status1 == 2 && $auding_status2 ==2){ // $auding_status2 数据库里的状态
                    if($role_id == 1 || $role_id == 2 || $role_id == 11){ //根据当前角色把当前角色变为失败
                        $data->auding_status1 = 3;
                    }
                    if($role_id == 12){
                        $data->auding_status2 = 3;
                    }
                    if($role_id == 13){
                        $data->auding_status3 = 3;
                    }
                    //sql里原数据 已经通过 在修改的话
                    $data->auding_status = 1;
                    $data->auding_status1 = 1;
                    $data->auding_status2 = 1;
                    $data->auding_status3 = 1;
                }else{
                    $data->auding_status = 2;
                    if(Request::instance()->controller() == 'Gift2'){

                        $data->sycs = Db::name('gift')->where('id',$data->id)->value('sycs')+Request::instance()->param('sycss');
                        $data->zcs = Db::name('gift')->where('id',$data->id)->value('zcs') + Request::instance()->param('sycss');
                        //Db::name('gift')->where('id',$data->id)->setField('sycss',0);
                        $data->sycss = 0;
                    }
                    if(Request::instance()->controller() == 'Gift'){

                        $data->sycs = Db::name('gift')->where('id',$data->id)->value('sycs')+Request::instance()->param('sycss');
                        $data->zcs = Db::name('gift')->where('id',$data->id)->value('zcs') + Request::instance()->param('sycss');
                        //Db::name('gift')->where('id',$data->id)->setField('sycss',0);

                    }

                    if(Request::instance()->controller() == 'SystemCard'){
                        if(Request::instance()->param('type') == 1){
                            $data->count = 10000;
                            $type_name = '年卡';
                        }else{
                            $data->count = Request::instance()->param('count');
                            $data->minus_count = Request::instance()->param('count');
                            $type_name = '次卡';
                        }
                        $data->sycs = Db::name('SystemCard')->where('id',$data->id)->value('sycs')+Request::instance()->param('sycss');
                        $data->zcs = Db::name('SystemCard')->where('id',$data->id)->value('zcs') + Request::instance()->param('sycss');
                    }
                }


            }else{
                // $data->auding_status = $data->auding_status;使用默认提交值
                $data->auding_status = 3; //必须失败 否则 默认提交过来的auding_status 自动还是变成 1 2 3 状态;
            }

        }else{
            $data->auding_status = 1;
            $data->auding_status1 = 1;
            $data->auding_status2 = 1;
            $data->auding_status3 = 1;
        }

    }


}
function auding($data)
{

    if (\request()->action() == 'create') {

        //有添加操作就是有权限 //有可能创建人就是审核人
        $data->create_time = date('Y-m-d H:i:s', time());
        $data->update_time = date('Y-m-d H:i:s', time());
        $data->create_id = Session::get('manage_id');
        $data->reason = '';

        if (isset($data->auding_status)) { //有审核状态 审核权限人
            //多次审核
            $role_id = session('role_id');
            //管理员2 一级审核员11 二级审核员12 三级审核员13
            if($role_id == 2 || $role_id == 11){
                $data->auding_status1 = $data->auding_status;

            }
            if($role_id == 12){
                $data->auding_status2 = $data->auding_status;
            }
            if($role_id == 13){
                $data->auding_status3 = $data->auding_status;
            }
            $data->auding_status = 1;
        }

    } else {

        if (isset($data->auding_status)) { //有审核状态 审核权限人 2是审核成功
            //多次审核
            $role_id = session('role_id');
            //管理员2 一级审核员11 二级审核员12 三级审核员13
            $status = false;
            $auding_status1 = Db::name(request()->controller())->where('id',$data->id)->value('auding_status1');
            $auding_status2 = Db::name(request()->controller())->where('id',$data->id)->value('auding_status2');
            $auding_status3 = Db::name(request()->controller())->where('id',$data->id)->value('auding_status3');
            if($role_id == 2 || $role_id == 11){
                $data->auding_status1 = $data->auding_status;
                if($data->auding_status == 2 && $auding_status2 == 2 && $auding_status3 ==2){ //这有这一种情况是审核通过 其他全部是失败
                    $status = true;
                }

            }
            if($role_id == 12){ //2级审核
                if($auding_status1 != 2){
                    fail('请等一级审核完毕');
                }
                $data->auding_status2 = $data->auding_status;
                if($data->auding_status == 2 && $auding_status1 == 2 && $auding_status3 ==2){ //这有这一种情况是审核通过 其他全部是失败
                    $status = true;
                }
            }
            if($role_id == 13){
                if($auding_status2 != 2 || $auding_status1 != 2){
                    fail('请等一、二级审核完毕');
                }
                $data->auding_status3 = $data->auding_status;
                if($data->auding_status == 2 && $auding_status1 == 2 && $auding_status2 ==2){ //这有这一种情况是审核通过 其他全部是失败
                    $status = true;
                }
            }
            if($role_id == 1){
                if($data->auding_status == 2){ //审核通过
                    $status = true;
                    $data->auding_status1 = 2;
                    $data->auding_status2 = 2;
                    $data->auding_status3 = 2;
                }else{
                    $data->auding_status1 = 1;
                    $data->auding_status2 = 1;
                    $data->auding_status3 = 1;
                }

            }
            if($status == true){
                if($auding_status3 == 2 && $auding_status1 == 2 && $auding_status2 ==2){ // $auding_status2 数据库里的状态
                    if($role_id == 1 || $role_id == 2 || $role_id == 11){ //根据当前角色把当前角色变为失败
                        $data->auding_status1 = 3;
                    }
                    if($role_id == 12){
                        $data->auding_status2 = 3;
                    }
                    if($role_id == 13){
                        $data->auding_status3 = 3;
                    }
                    //sql里原数据 已经通过 在修改的话
                    $data->auding_status = 1;
                    $data->auding_status1 = 1;
                    $data->auding_status2 = 1;
                    $data->auding_status3 = 1;
                }else{
                    $data->auding_status = 2;
                    if(Request::instance()->controller() == 'Gift'){
                        $data->sycs = Db::name('gift')->where('id',$data->id)->value('sycs')+Request::instance()->param('sycss');
                        $data->zcs = Db::name('gift')->where('id',$data->id)->value('zcs') + Request::instance()->param('sycss');
                        //Db::name('gift')->where('id',$data->id)->setField('sycss',0);
                        $data->sycss = 0;
                    }

                    if(Request::instance()->controller() == 'SystemCard'){
                        if(Request::instance()->param('type') == 1){
                            $data->count = 10000;
                            $type_name = '年卡';
                        }else{
                            $data->count = Request::instance()->param('count');
                            $data->minus_count = Request::instance()->param('count');
                            $type_name = '次卡';
                        }
                        $data->sycs = Db::name('SystemCard')->where('id',$data->id)->value('sycs')+Request::instance()->param('sycss');
                        $data->zcs = Db::name('SystemCard')->where('id',$data->id)->value('zcs') + Request::instance()->param('sycss');
                    }
                }


            }else{
               // $data->auding_status = $data->auding_status;使用默认提交值
               $data->auding_status = 3; //必须失败 否则 默认提交过来的auding_status 自动还是变成 1 2 3 状态;
            }

        }else{
            $data->auding_status = 1;
            $data->auding_status1 = 1;
            $data->auding_status2 = 1;
            $data->auding_status3 = 1;
        }

    }


}


function audingcc($data)
{
    if (\request()->action() == 'create') {
        //有添加操作就是有权限 //有可能创建人就是审核人
        $data->create_time = date('Y-m-d H:i:s', time());
        $data->update_time = date('Y-m-d H:i:s', time());
        $data->create_id = Session::get('manage_id');
        $data->reason = '';

        if (isset($data->auding_status)) { //有审核状态 审核权限人
            //多次审核
            $role_id = session('role_id');
            //管理员2 一级审核员11 二级审核员12 三级审核员13

            if($role_id == 2 || $role_id == 11 || $role_id == 1){
                $data->auding_status1 = $data->auding_status;

            }
            if($role_id == 12){
                $data->auding_status2 = $data->auding_status;
            }
            if($role_id == 13){
                $data->auding_status3 = $data->auding_status;
            }
            $data->auding_status = 1;
        }

    } else {
        if (isset($data->auding_status)) { //有审核状态 审核权限人 2是审核成功
            //多次审核
            $role_id = session('role_id');
            //管理员2 一级审核员11 二级审核员12 三级审核员13
            $status = false;
            $auding_status1 = Db::name(request()->controller())->where('id',$data->id)->value('auding_status1');
            $auding_status2 = Db::name(request()->controller())->where('id',$data->id)->value('auding_status2');
            $auding_status3 = Db::name(request()->controller())->where('id',$data->id)->value('auding_status3');
            if($role_id == 2 || $role_id == 11){
                $data->auding_status1 = $data->auding_status;
                if($data->auding_status == 2 && $auding_status2 == 2 && $auding_status3 ==2){ //这有这一种情况是审核通过 其他全部是失败
                    $status = true;
                }

            }
            if($role_id == 12){ //2级审核
                if($auding_status1 != 2){
                    fail('请等一级审核完毕');
                }
                $data->auding_status2 = $data->auding_status;
                if($data->auding_status == 2 && $auding_status1 == 2 && $auding_status3 ==2){ //这有这一种情况是审核通过 其他全部是失败
                    $status = true;
                }
            }
            if($role_id == 13){
                if($auding_status2 != 2 || $auding_status1 != 2){
                    fail('请等一、二级审核完毕');
                }
                $data->auding_status3 = $data->auding_status;
                if($data->auding_status == 2 && $auding_status1 == 2 && $auding_status2 ==2){ //这有这一种情况是审核通过 其他全部是失败
                    $status = true;
                }
            }
            if($role_id == 1){
                if($data->auding_status == 2){ //审核通过
                    $status = true;
                    $data->auding_status1 = 2;
                    $data->auding_status2 = 2;
                    $data->auding_status3 = 2;
                }else{
                    $data->auding_status1 = 1;
                    $data->auding_status2 = 1;
                    $data->auding_status3 = 1;
                }
            }
            if($status == true){
                if($auding_status3 == 2 && $auding_status1 == 2 && $auding_status2 ==2){
                    if($role_id == 1 || $role_id == 2 || $role_id == 11){ //根据当前角色把当前角色变为失败
                        $data->auding_status1 = 3;
                    }
                    if($role_id == 12){
                        $data->auding_status2 = 3;
                    }
                    if($role_id == 13){
                        $data->auding_status3 = 3;
                    }
                    //sql里原数据 已经通过 在修改的话
                    $data->auding_status = 1;
                    $data->auding_status1 = 1;
                    $data->auding_status2 = 1;
                    $data->auding_status3 = 1;
                    Db::name('member_coupon')->where('coupon_id',$data->id)->setField('auding_status',1);
                }else{
                    $data->auding_status = 2;//总审核
                    Db::name('member_coupon')->where('coupon_id',$data->id)->setField('auding_status',2);
                    foreach (explode(',',Db::name('coupon')->where('id',$data->id)->value('shop_assignor_id')) as $k => $v){
                        (new \app\index\controller\MemberMessage())->jpushMessage($v,'恭喜您获得优惠券'.Db::name('coupon')->where('id',$data->id)->value('number').'张',Db::name('coupon')->where('id',$data->id)->value('title'),3);
                    }
                }

            }else{
                // $data->auding_status = $data->auding_status;使用默认提交值
                $data->auding_status = 3; //必须失败 否则 默认提交过来的auding_status 自动还是变成 1 2 3 状态;
                Db::name('member_coupon')->where('coupon_id',$data->id)->setField('auding_status',1);
            }

        }

    }


}


function audingbefore($data){
    if(\request()->action() == 'create'){
        //有添加操作就是有权限
        $data->create_time = date('Y-m-d H:i:s',time());
        $data->update_time = date('Y-m-d H:i:s',time());
        $data->create_id = Session::get('manage_id');
        $data->reason = '';
    }else{
        //创建人和审核人 都只用修改操作 创建人创建审核人审核会再次修改时间 error
        //只有创建人和修改的人是同一人才可以修改时间（包括审核人和创建人都可以）
        $create_id = Db::name(request()->controller())->where('id',$data->id)->value('create_id');
        if($create_id == Session::get('manage_id')){
            $data->update_time = date('Y-m-d H:i:s',time());
        }

    }
    if(isset($data->auding_status)){ //有审核状态 审核权限人
        //多次审核

       if(isset($data->id)){ //是修改操作
           $auding_status = Db::name(request()->controller())->where('id',$data->id)->value('auding_status');
           if($auding_status != $data->auding_status){ //数据里的默认1和当前提交的 不一致才录入审核数据; 如果是1相等审核不录入，2 3 加入审核数据
               if($data->auding_status == 1){
                   $data->auding_id = Session::get('manage_id');
                   $data->reason = '';
                   $data->auding_time = date('Y-m-d H:i:s',time());
               }
               if($data->auding_status == 2){
                   $data->auding_id = Session::get('manage_id');
                   $data->auding_time = date('Y-m-d H:i:s',time());
                   $data->reason = '';
               }
               if($data->auding_status == 3){
                   $data->auding_id = Session::get('manage_id');
                   $data->auding_time = date('Y-m-d H:i:s',time());
               }
           }
       }else{
           if($data->auding_status == 1){
               $data->auding_id = Session::get('manage_id');
               $data->reason = '';
               $data->auding_time = date('Y-m-d H:i:s',time());
           }
           if($data->auding_status == 2){
               $data->auding_id = Session::get('manage_id');
               $data->auding_time = date('Y-m-d H:i:s',time());
               $data->reason = '';
           }
           if($data->auding_status == 3){
               $data->auding_id = Session::get('manage_id');
               $data->auding_time = date('Y-m-d H:i:s',time());
           }
       }

    }

}

function auding_status($id,$field){
    Db::name(request()->controller())->where('id',$id)->update(['delete_time' => date('Y-m-d H:i:s',time()),'is_delete' => 2,'delete_id' => session('manage_id')]);
    $title = Db::name(request()->controller())->where('id',$id)->value($field);
    Db::name('recycle_bin')->insert(['title' => $title,'type' =>'用户管理','table' => 'news','table_id' => $id,'delete_id' => Session::get('manage_id'),'delete_time' => date('Y-m-d H:i:s',time())]);
}

function hideStr($string, $bengin = 0, $len = 4, $type = 0, $glue = "@")
{
    if (empty($string))
        return false;
    $array = array();
    if ($type == 0 || $type == 1 || $type == 4) {
        $strlen = $length = mb_strlen($string);
        while ($strlen) {
            $array[] = mb_substr($string, 0, 1, "utf8");
            $string = mb_substr($string, 1, $strlen, "utf8");
            $strlen = mb_strlen($string);
        }
    }
    switch ($type) {
        case 1:
            $array = array_reverse($array);
            for ($i = $bengin; $i < ($bengin + $len); $i++) {
                if (isset($array[$i]))
                    $array[$i] = "*";
            }
            $string = implode("", array_reverse($array));
            break;
        case 2:
            $array = explode($glue, $string);
            $array[0] = hideStr($array[0], $bengin, $len, 1);
            $string = implode($glue, $array);
            break;
        case 3:
            $array = explode($glue, $string);
            $array[1] = hideStr($array[1], $bengin, $len, 0);
            $string = implode($glue, $array);
            break;
        case 4:
            $left = $bengin;
            $right = $len;
            $tem = array();
            for ($i = 0; $i < ($length - $right); $i++) {
                if (isset($array[$i]))
                    $tem[] = $i >= $left ? "*" : $array[$i];
            }
            $array = array_chunk(array_reverse($array), $right);
            $array = array_reverse($array[0]);
            for ($i = 0; $i < $right; $i++) {
                $tem[] = $array[$i];
            }
            $string = implode("", $tem);
            break;
        default:
            for ($i = $bengin; $i < ($bengin + $len); $i++) {
                if (isset($array[$i]))
                    $array[$i] = "*";
            }
            $string = implode("", $array);
            break;
    }
    return $string;

}
/**
+----------------------------------------------------------
 * 将一个字符串部分字符用*替代隐藏
+----------------------------------------------------------
 * @param string    $string   待转换的字符串
 * @param int       $bengin   起始位置，从0开始计数，当$type=4时，表示左侧保留长度
 * @param int       $len      需要转换成*的字符个数，当$type=4时，表示右侧保留长度
 * @param int       $type     转换类型：0，从左向右隐藏；1，从右向左隐藏；2，从指定字符位置分割前由右向左隐藏；3，从指定字符位置分割后由左向右隐藏；4，保留首末指定字符串
 * @param string    $glue     分割符
+----------------------------------------------------------
 * @return string   处理后的字符串
+----------------------------------------------------------
 */

function cut_str($string, $sublen, $start = 0, $code = 'UTF-8')
  {
         if($code == 'UTF-8')
            {
                 $pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
          preg_match_all($pa, $string, $t_string);

          if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen));
          return join('', array_slice($t_string[0], $start, $sublen));
     }
     else
     {
                 $start = $start*2;
         $sublen = $sublen*2;
         $strlen = strlen($string);
         $tmpstr = '';

         for($i=0; $i< $strlen; $i++)
                     {
                        if($i>=$start && $i< ($start+$sublen))
                             {
                                 if(ord(substr($string, $i, 1))>129)
                                     {
                                         $tmpstr.= substr($string, $i, 2);
                 }
                 else
                 {
                                         $tmpstr.= substr($string, $i, 1);
                 }
             }
             if(ord(substr($string, $i, 1))>129) $i++;
         }
         //if(strlen($tmpstr)< $strlen ) $tmpstr.= "...";
         return $tmpstr;
     }
 }

/**
 * @param string $dirName
 * 删除文件函数
 */
function delFileUnderDir($dirName = '')

{

    if ($handle = opendir($dirName)) {

        while (false !== ($item = readdir($handle))) {

            if ($item != "." && $item != "..") {

                if (is_dir($dirName)) {

                    delFileUnderDir($dirName);

                } else {//开源代码phpfensi.com

                    if (unlink($dirName)) echo "成功删除文件： $dirName / $item < br />n";

                }

            }

        }

        closedir($handle);

    }

}

function set_finance_order($member_id, $create_shop_id = 0)
{
    $find = Db::name('member')->where('id',$member_id)->find();
    if ($find['salesman_id'] > 0) {
        return 1; //业务员订单
    }
    if ($find['salesman_id'] == 0 && $find['shop_invite_id'] > 0) {
        return 2; //门店二维码订单
    }
    if ($find['salesman_id'] == 0 && $find['shop_invite_id'] == 0 && $create_shop_id > 0) {
        return 3; //门店创建订单
    }
    return 4;//普通用户订单
}


function writeLogPic($data){
    $years = date('Y-m-d');
    //设置路径目录信息
    $url = './certification/'.$years.'/'.request()->controller().'_'.request()->action().'.txt';
    $dir_name=dirname($url);
    //目录不存在就创建
    if(!file_exists($dir_name))
    {
        //iconv防止中文名乱码
        $res = mkdir(iconv("UTF-8", "GBK", $dir_name),0777,true);
    }
    $fp = fopen($url,"a");//打开文件资源通道 不存在则自动创建
    fwrite($fp,date('Y-m-d H:i:s',time()).' '.var_export($data,true)."\r\n");//写入文件
    fclose($fp);//关闭资源通道
}

function getAppType()
{
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')) {
        return 'systerm is IOS';
    } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'Android')) {
        return 'systerm is Android';
    } else {
        return 'systerm is other';
    }
}


/**
 * PHP判断用户访问的操作系统,以及iOS的设备
 * @return string
 */
function getOS()
{
    $agent = strtolower($_SERVER['HTTP_USER_AGENT']);

    if (strpos($agent, 'windows nt')) {
        $platform = 'windows';
    } elseif (strpos($agent, 'macintosh')) {
        $platform = 'mac';
    } elseif (strpos($agent, 'ipod')) {
        $platform = 'ipod';
    } elseif (strpos($agent, 'ipad')) {
        $platform = 'ipad';
    } elseif (strpos($agent, 'iphone')) {
        $platform = 'iphone';
    } elseif (strpos($agent, 'android')) {
        $platform = 'android';
    } elseif (strpos($agent, 'unix')) {
        $platform = 'unix';
    } elseif (strpos($agent, 'linux')) {
        $platform = 'linux';
    } else {
        $platform = 'other';
    }
    return $platform;
}